package com.example.hzz.simpleplayer;

import android.app.Fragment;
import android.app.FragmentManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;


/**
 * Created by huangzezhan on 2018/9/13.
 */

public abstract class SingleFragmentActivity extends FragmentActivity {

    private Fragment fragment;

    abstract Fragment createFragment();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.single_fragment_layout);
        FragmentManager fg = getFragmentManager();
        fragment = fg.findFragmentById(R.id.container_fragment);
        if (fragment == null) {
            fragment = createFragment();
            fg.beginTransaction()
                    .add(R.id.container_fragment, fragment)
                    .commit();
        }

    }
}
